var e = require("../../@babel/runtime/helpers/interopRequireDefault"), r = e(require("../../@babel/runtime/regenerator")), t = require("../../@babel/runtime/helpers/asyncToGenerator"), n = e(require("../../utils/api")), a = getApp();

Page({
    data: {
        clicked: !1
    },
    onShow: function() {
        this.getUserInfoDebounce = this.debounce(this.getUserInfo, 600, !1);
    },
    debounce: function(e, r) {
        var t = arguments.length > 2 && void 0 !== arguments[2] && arguments[2], n = null;
        return function() {
            var a = arguments, o = this;
            n && clearTimeout(n), t ? (n || e.apply(this, arguments), n = setTimeout(function() {
                n = null;
            }, r)) : n = setTimeout(function() {
                e.apply(o, a);
            }, r);
        };
    },
    getUserInfo: function() {
        var e = this;
        return t(r.default.mark(function o() {
            return r.default.wrap(function(o) {
                for (;;) switch (o.prev = o.next) {
                  case 0:
                    if (!e.data.clicked) {
                        o.next = 2;
                        break;
                    }
                    return o.abrupt("return");

                  case 2:
                    e.setData({
                        clicked: !0
                    }), wx.getUserProfile({
                        desc: "业务需要",
                        success: function() {
                            var e = t(r.default.mark(function e(t) {
                                var o, s, u;
                                return r.default.wrap(function(e) {
                                    for (;;) switch (e.prev = e.next) {
                                      case 0:
                                        return a.globalData.authorized = !0, (o = wx.getStorageSync("openid")) || wx.redirectTo({
                                            url: "/pages/login/login"
                                        }), e.prev = 3, e.next = 6, n.default.member({
                                            openid: o,
                                            headImg: t.userInfo.avatarUrl
                                        });

                                      case 6:
                                        a.globalData.userInfo.headImg = t.userInfo.avatarUrl, e.next = 12;
                                        break;

                                      case 9:
                                        e.prev = 9, e.t0 = e.catch(3), console.log(e.t0.msg);

                                      case 12:
                                        return e.prev = 12, e.next = 15, n.default.signIn({
                                            openid: o
                                        });

                                      case 15:
                                        s = e.sent, u = "", s.result.rewards.forEach(function(e, r) {
                                            u += 0 === r ? e.name + " +" + e.rewardAdd : "\r\n" + e.name + " +" + e.rewardAdd;
                                        }), "" !== u && wx.showToast({
                                            title: u,
                                            icon: "none",
                                            duration: 2e3
                                        }), e.next = 24;
                                        break;

                                      case 21:
                                        e.prev = 21, e.t1 = e.catch(12), console.log(e.t1.msg);

                                      case 24:
                                        wx.switchTab({
                                            url: "/pages/index/index"
                                        });

                                      case 25:
                                      case "end":
                                        return e.stop();
                                    }
                                }, e, null, [ [ 3, 9 ], [ 12, 21 ] ]);
                            }));
                            return function(r) {
                                return e.apply(this, arguments);
                            };
                        }(),
                        fail: function(e) {
                            console.log(e);
                        }
                    });

                  case 4:
                  case "end":
                    return o.stop();
                }
            }, o);
        }))();
    },
    bindGetUserInfo: function(e) {
        return t(r.default.mark(function t() {
            var o, s, u;
            return r.default.wrap(function(r) {
                for (;;) switch (r.prev = r.next) {
                  case 0:
                    return a.globalData.authorized = !0, o = wx.getStorageSync("openid"), r.prev = 2, 
                    r.next = 5, n.default.member({
                        openid: o,
                        headImg: e.detail.userInfo.avatarUrl
                    });

                  case 5:
                    a.globalData.userInfo.headImg = e.detail.userInfo.avatarUrl, r.next = 11;
                    break;

                  case 8:
                    r.prev = 8, r.t0 = r.catch(2), console.log(r.t0.msg);

                  case 11:
                    return r.prev = 11, r.next = 14, n.default.signIn({
                        openid: o
                    });

                  case 14:
                    s = r.sent, u = "", s.result.rewards.forEach(function(e, r) {
                        u += 0 === r ? e.name + " +" + e.rewardAdd : "\r\n" + e.name + " +" + e.rewardAdd;
                    }), "" !== u && wx.showToast({
                        title: u,
                        icon: "none",
                        duration: 2e3
                    }), r.next = 23;
                    break;

                  case 20:
                    r.prev = 20, r.t1 = r.catch(11), console.log(r.t1.msg);

                  case 23:
                    wx.switchTab({
                        url: "/pages/index/index"
                    });

                  case 24:
                  case "end":
                    return r.stop();
                }
            }, t, null, [ [ 2, 8 ], [ 11, 20 ] ]);
        }))();
    }
});